#!/usr/bin/env python3
# set coding: utf-8
"""
@Project : litewaf2
@File :    con_request.py
@Time :    2023/3/27 10:30
@Author :  richard zhu
@Email :   gaotao.zhugt@dtzhejiang.com
@purpose : 
"""
import time
from threading import Thread
import queue
import requests

all = queue.Queue(maxsize=10)
faild = queue.Queue(maxsize=10)
all.put(0)
faild.put(0)

def query(url, header):
    r = requests.get(url=url, headers=header, timeout=10)
    # print(r.text)
    a = all.get()
    a += 1
    all.put(a)
    if r.status_code != 200:
        f = faild.get()
        f += 1
        faild.put(f)

def main():
    t_list = []
    # url = "http://192.168.218.135:8088/?id=123"
    # url = "http://ip.gaotao.club:8088/?id=123"
    url = "http://ip.gaotao.club:8088"
    # url = "http://zabbix.sz-ops.zjzwfw.gov.cn/ngx_status/"
    header = {"host": "ip.gaotao.club"}
    # header = {"host": "zabbix.sz-ops.zjzwfw.gov.cn"}

    for i in range(20):
        t = Thread(target=query, args=(url, header))
        t_list.append(t)
        # time.sleep(0.01)
        t.start()

    for t in t_list:
        t.join()

    print("总：",all.get())
    print("失败：", faild.get())

if __name__ == '__main__':

    main()
